import axiosInstance from '@/utils/request'

// 获取地址列表
export const getAddressListApi = () => {
  return axiosInstance.get('/address/list')
}

// 修改默认地址
export const editDefaultAddressApi = (addressId) => {
  return axiosInstance.post('/address/setDefault', {
    addressId
  })
}

// 请求默认地址id
export const getDefaultAddressIdApi = () => {
  return axiosInstance.get('/address/defaultId')
}

// 请求省市区数据
export const getRegionApi = () => {
  return axiosInstance.get('/region/tree')
}

// 编辑地址 id 对应的收货地址
export const editAddressApi = ({addressId, name, phone, regions, detail}) => {
  return axiosInstance.post('/address/edit', {
    addressId, // 地址列表中哪一个地址的 id
    form: {
      name, // 名字
      phone, // 手机
      region: regions, // 省市区信息
      detail // 详细地址
    }
  })
}

// 删除地址 id 对应的收货地址
export const removeAddressApi = (addressId) => {
  return axiosInstance.post('/address/remove', {
    addressId
  })
}

// 添加收货地址
export const addAddressApi = ({name, phone, regions, detail}) => {
  return axiosInstance.post('/address/add', {
    form: {
      name,
      phone,
      region: regions,
      detail
    }
  })
}
